var mailer = require('nodemailer');
var config = require('../../config');
var util = require('util');
var transport = mailer.createTransport('SMTP', config.mail_opts);
var log4js = require('log4js');
var logger = log4js.getLogger('normal');


module.exports = {

    /**
     *
     {
     from: from,
     to: to,
     subject: subject,
     html: html
     }
     * @param data
     */
    sendMail:function(data){
        if (config.dev === 'DEV') {
            return;
        }
        // 遍历邮件数组，发送每一封邮件，如果有发送失败的，就再压入数组，同时触发mailEvent事件
        transport.sendMail(data, function (err) {
            if (err) {
                // 写为日志
                console.log(err);
                logger.error(err);
            }
        });
    }
}